home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000108_icon-group-sender _Thu Oct 30 13:21:36 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  6KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.7/8.8.7) with SMTP id NAA21178
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Thu, 30 Oct 1997 13:21:35 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA29172; Thu, 30 Oct 1997 13:21:35 -0700
  7. From: gep2@computek.net
  8. Date: Thu, 30 Oct 1997 12:53:03 -0600
  9. Message-Id: <199710301853.MAA25014@axp.cmpu.net>
  10. Mime-Version: 1.0
  11. Content-Type: text/plain
  12. Content-Transfer-Encoding: 7bit
  13. Subject: problem with data type in program
  14. To: icon-group@optima.CS.Arizona.EDU
  15. X-Mailer: SPRY Mail Version: 04.00.06.17
  16. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  17. Status: RO
  18.  
  19. >The problem is this.  I am getting error messages saying that the main
  20. procedure expects a table does not get one from the procedure it
  21. invokes--namely, scantext(). But it looks to me as if the value returned
  22. by scantext() should be a table.  What am I doing wrong?
  23.  
  24. >Thanks in advance for any help.
  25.  
  26. The most basic debugging technique for a situation like this is to make sure 
  27. that the program is ACTUALLY running the way you EXPECTED it to... that data 
  28. values are as you expected, that transfers of control are taking place the way 
  29. you wanted them to, etc. etc.  And it helps if, when writing a program, you can 
  30. design in features to facilitate the initial debugging... and such that they can 
  31. be turned off or removed (ideally, progressively) after parts or all of the 
  32. program are working.  And part of designing in debugging output is knowing where 
  33. you should and shouldn't put it, so that you get useful output without drowning 
  34. in it.  :-)
  35.  
  36. Let me take your program and show you, for example, what kind of debugging 
  37. output I'm talking about (and note that there is no one way to do stuff like 
  38. this... you might want more or less... or even done differently... but at least 
  39. putting stuff like the following in, and STUDYING WHAT OUTPUT the program then 
  40. produces, will help you to understand what your program REALLY does (and, 
  41. especially for beginning programmers but sometimes even for us experienced ones, 
  42. programs do NOT always follow what my CS professor used to call "The Principle 
  43. of Least Astonishment"....  :-)
  44.  
  45. I will not mark quotes during the program text, but will indicate my additions 
  46. by using a ">>>>>>" at the beginning of the example debugging lines I've added.
  47.  
  48.  
  49. ############################################################################
  50. #
  51. #       File:     tabulate_AO_person.icn
  52. #       Subject:  Program to tabulate person of A and O
  53. #       Author:   Stuart P. Robinson
  54. #       Date:     14 October, 1997
  55. #
  56. ############################################################################
  57. #
  58. #  This program was written to calculate what proportion of A's and O's 
  59. #  are 1st, 2nd, or 3rd person. Unlike previous version, it does NOT give 
  60. #  percentages--just raw numbers. The 7 logical possibilities it counts are:
  61. #  
  62. #     1.    1-2         first_on_second
  63. #     2.    1-3         first_on_third
  64. #     3.    2-1         second_on_first
  65. #     4.    2-3         second_on_third
  66. #     5.    3-1         third_on_first
  67. #     6.    3-2         third_on_second
  68. #     7.    3-3         third_on_third
  69. #
  70. ############################################################################
  71.  
  72. procedure main()
  73.  
  74. >>>>>> write("procedure main starting")
  75.  
  76.    output := sort( scan_text(), 1 )
  77.  
  78. >>>>>> write("size of output after sorting is ",*output)
  79.  
  80.    write( "Person Config." || "/t" || "No." )
  81.    every x := key( output ) do
  82.       write( x || "\t" || output[x] )
  83.  
  84. >>>>>> write("procedure main is finished")
  85.  
  86. end
  87.  
  88.  
  89.  
  90. procedure scan_text( )
  91.    value_table := table( 0 )
  92.  
  93. >>>>>> write("scan_text starting")
  94.  
  95.    while line := read()
  96.    do
  97.       {
  98.  
  99. >>>>>> write("processing line: '",line,"'")
  100.  
  101.       line ?
  102.          {
  103.          value_table[ search_line() ] +:= 1
  104.          }
  105.       }
  106.  
  107. >>>>>> write("scan_text is returning a value of type ",type(value_table))
  108.  
  109. return value_table
  110. end
  111.  
  112.  
  113.  
  114. procedure search_line( )
  115.  
  116. >>>>>> write("search_line starting")
  117.  
  118.    chars := &letters++&digits++'{`'
  119.    subject := 0
  120.    object := 0
  121.  
  122.    if find( "{Q" ) then
  123.       while tab( upto( chars ) ) do 
  124.          {
  125.          word := tab( many( chars ) )
  126.  
  127. >>>>>> write("  word found: '",word,"'")
  128.  
  129.          word ?
  130.             {
  131.             if tab( find( "{" ) ) then
  132.                word := tab( 0 )
  133.  
  134. >>>>>> write("  case statement test being started with word: '",word,"'")
  135.  
  136.                case word of
  137.                   {
  138.                   "{A1" :  subject := 1
  139.                   "{A2" :  subject := 2
  140.                   "{A"  :  subject := 3
  141.  
  142.                   "{O1" :  object := 1
  143.                   "{O2" :  object := 2
  144.                   "{O"  :  object := 3
  145.                   }
  146.                }
  147.             }
  148.  
  149. >>>>>> write("  after case statement test, subject=",subject," object=",object)
  150.  
  151.    if subject == 1 then
  152.       if object == 2 then type := "first on second"
  153.       else if object == 3 then type := "first on third"
  154.  
  155.    if subject == 2 then 
  156.       if object == 1 then type := "second on first"
  157.       else if object == 3 then type := "second on third"
  158.  
  159.    if subject == 3 then
  160.       if object == 1 then type := "third on first"
  161.       else if object == 2 then type := "third on second"
  162.       else if object == 3 then type := "third on third"
  163.  
  164. >>>>>> write("search_line is returning '",type,"'")
  165.  
  166. return type
  167. end
  168.  
  169.  
  170. Running the program with that debugging output, and STUDYING THE RESULT, will 
  171. help you to understand how the program you've written is ACTUALLY working, and 
  172. help you to see where it's not ACTUALLY working the way you intended for it to.
  173.  
  174. Gordon Peterson
  175. http://www.computek.net/public/gep2/
  176. Support the Anti-SPAM Amendment!  Join at http://www.cauce.org/
  177.  
  178.